<template>
  <div class="zero-drift tapStyle secondary-page-mode">
    <div class="currency-mode-wrap">
      <div class="tablebox" style="height: 100%">
        <el-table
          :data="tableData"
          border
          height="100%"
          :span-method="objectSpanMethod"
          v-loading="loading"
          element-loading-text="加载中"
          element-loading-spinner="loading-type-a"
          element-loading-background="rgba(255, 255, 255, 1)"
          style="width: 100%">
          <el-table-column
            type="index"
            label="序号"
            :index="indexMethod"
            width="50">
          </el-table-column>
          <el-table-column
            prop="indexName"
            label="类别">
          </el-table-column>
          <el-table-column
            prop="parameterName"
            label="参数名称">
          </el-table-column>
        
          <el-table-column
            prop="parameterValue"
            label="参数值">
          </el-table-column>
          <el-table-column
            prop="parameterUnit"
            label="单位">
          </el-table-column>
       
          <el-table-column
            prop="operation"
            label="操作">
            <template slot-scope="scope">
              <el-button type='secondBtn' @click="setParameter(scope.row)">设置</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-dialog
      width="280px"
      title="参数设置"
      :visible.sync="parameter" >
        <div class="parameter-wrap">
           <div class="parameter-row">
             <span class="label-text">参数值：</span>
             <div class="layoutBox" style="width:160px">
                <el-input v-model="paramValue" placeholder="请输入内容"></el-input>
             </div>
           </div>
         
          <div class="parameter-row" style="text-align: center;margin-top: 20px;">
              <el-button @click="sureSet">&nbsp; 确定 &nbsp;</el-button>
          </div>
        </div>
    </el-dialog>

  </div>
</template>

<script>
  export default {
    name: "",
    data() {
      return {
        timing:60,//倒计时秒数
        refreshTime:new Date().format('yyyy-MM-dd hh:mm:ss'),//页面数据刷新时间
        tableData:[],
        parameter:false,
        paramValue:'',
        parameterId:'',//因子参数数据ID
        stationId:'',//站点ID
        loading:true,
      };
    },
    methods:{
      adda(index,prop,key){
        let name = this.tableData[index][prop];
        let row = 0;
        for(let i=index;i<this.tableData.length;i++){
          if(name == this.tableData[i][prop]){
            row++
          }else{
            break;
          }
        }
        this.tableData[index][key] = row;
        return row
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 1) {
          if(row.sf){
            return{
              colspan:1,
              rowspan:row.sf
            }
          }else{
            return{
              colspan:1,
              rowspan:0
            }
          }
        }
      },
      setParameter(row){
        this.parameter = true;
        this.parameterId=row.parameterId
        
      },
      sureSet(){
          this.$http.get("/Quality/qualityControlSet/editorEquipmentParameter", {
             params: {
                parameterId: this.parameterId,
                parameterValue:this.paramValue
             }
           }).then(res=>{
               this.paramValue='';
               this.parameter=false;
               this.getTableData()
           });
      },
      getTableData(){
          this.loading=true;
           this.$http.get("/Quality/qualityControlSet/getEquipmentParameter", {
             params: {
                stationCodes: this.stationId 
             }
           }).then(res=>{
               
                this.tableData=res.data.content.dataList;
                for(let i=0;i<this.tableData.length;i++){
                  let num = this.adda(i,'indexName','sf');
                        i+=num-1
                };
                this.loading=false;
           })
      }
    },
    mounted(){
      // this.createdChart();
    },
    computed: {
        stationInfo: {
            get: function() {
              return this.$store.state.stationInfo;
            }
        }
    },
    watch: {
      stationInfo(value) {
        if (value.length > 0) {
          this.stationId = value[0].nodeId;
          this.getTableData()
        }
      }
    },
    created() {
      this.$store.commit("setShowlefttree", true);
     
    }
  };
</script>

<style scoped lang="less">
  .zero-drift .currency-mode-wrap{
    padding: 0;
    border: none;
    margin-top: 0;
    height: 100%;
  }
  .timing-text{
    font-size: 16px;
    b{
      display: inline-block;
      width: 24px;
    }
  }
  .fault,.abnormal,.normal{
    i{
      display: inline-block;
      vertical-align: middle;
      margin-bottom: 2px;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #c64522;
      margin-right: 3px;
    }
  }
  .abnormal i{
    background: #c64522;
  }
  .normal i{
    background: #67c622;
  }
  .fault i{
    background: #dfae1c;
  }
  .label-text{
    display: inline-block;
    width: 70px;
    vertical-align: middle;
  }
  .parameter-row{
    padding: 4px 0;
  }
</style>

